package de.codi.similarity.sparematrix.merger;

import java.util.Map;

import de.codi.CODISettings;

public class WeightMerger implements SpareMatrixMerger {

	@Override
	public double getConfValue(Map<Integer, Double> value) {
		double conf = 0;
		double weight;
		double weightSum = 0;

		for (Integer id : value.keySet()) {
			if (id == 0)
				continue;
			switch (id) {
			case 1:
				weight = CODISettings.jaroWinklerWeight;
				break;
			case 2:
				weight = CODISettings.levenstheinWeight;
				break;
			case 3:
				weight = CODISettings.cosineWeight;
				break;
			case 4:
				weight = CODISettings.jaccardWeight;
				break;
			case 5:
				weight = CODISettings.smithWatermanGotohWeight;
				break;
			case 6:
				weight = CODISettings.overlapCoefficientWeight;
				break;
			case 7:
				weight = CODISettings.jakobTimoWeight;
				break;
			case 8:
			    weight = CODISettings.fastJoinWeight;
			default:
				weight = 0;
			}
			conf += value.get(id) * weight;
			if (value.get(id) != 0) {
				weightSum += weight;
			}
		}
		if (weightSum == 0) {
			weightSum = 1.0;
		}
		return conf / weightSum;
	}
}
